#include<iostream>
#include <unistd.h>
using namespace std;

int main(){
	std::cout<<"fork之前"<<std::endl;
	pid_t id=fork();
	if(id<0){
		std::cout<<"fork失败!"<<std::endl;
	}
	else if(id==0){
		while(1){
			std::cout<<"我是子进程,pid:"<<getpid()<<",ppid:"<<getppid()<<std::endl;
			sleep(1);
		}
	}
	else{
		while(1){
			std::cout<<"我是父进程,pid:"<<getpid()<<",ppid:"<<getppid()<<std::endl;
			sleep(1);
		}
	}
	return 0;
}
